<?php
class SiteToolRelation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'site_tools';
	}
	
	public function relations()
	{
		return array(
			'tool'=>array(self::BELONGS_TO, 'Tools', 'tool_ID'),
			'site'=>array(self::BELONGS_TO, 'Sites', 'site_ID'),
		);
	}
	
	public function replaceRecord($site_ID, $tool_ID)
	{
		$connection = Yii::app()->db;
		$sql = "REPLACE INTO ".$this->tableName()." VALUES ($site_ID, $tool_ID)";
		$command = $connection->createCommand($sql);
		$rows = $command->execute();
	}
	
	public function deleteRecord($site_ID, $tool_ID)
	{
		$connection = Yii::app()->db;
		$sql = "DELETE FROM ".$this->tableName()." WHERE site_ID=$site_ID and tool_ID=$tool_ID";
		$command = $connection->createCommand($sql);
		$rows = $command->execute();		
	}
}
?>
